import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 用户信息 */
export interface User {
  [x: string]: any
  openid: string // 微信OpenID
  unionid: string // 微信UnionID
  nickname?: string // 用户昵称
  avatar: string // 用户头像
  role?: string // 用户角色
  status?: number // 用户状态
  isMember?: boolean // 会员状态
  creator: string // 创建者
  createTime: string | Dayjs // 创建时间
  updater: string // 更新者
  updateTime: string | Dayjs // 更新时间
  deleted: boolean // 是否删除
  notification: number // 通知开关（默认开启）
  autoPlay: number // 播放设置
}

// 用户 API
export const UserApi = {
  // 查询用户分页
  getUserPage: async (params: any) => {
    console.log('success', params)
    return await request.get({ url: `/pickbook/user/page`, params })
  },

  // 查询用户详情
  getUser: async (id: number) => {
    return await request.get({ url: `/pickbook/user/get?id=${id}` })
  },

  // 新增用户
  createUser: async (data: User) => {
    return await request.post({ url: `/pickbook/user/create`, data })
  },

  // 修改用户
  updateUser: async (data: User) => {
    return await request.put({ url: `/pickbook/user/update`, data })
  },

  // 删除用户
  deleteUser: async (id: number) => {
    return await request.delete({ url: `/pickbook/user/delete?id=` + id })
  },

  /** 批量删除用户 */
  deleteUserList: async (ids: number[]) => {
    return await request.delete({ url: `/pickbook/user/delete-list?ids=${ids.join(',')}` })
  },

  // 导出用户 Excel
  exportUser: async (params) => {
    return await request.download({ url: `/pickbook/user/export-excel`, params })
  }
}
